﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wicresoft.EKA.NRemedy.CodeGenerator.WinForm
{
    // Implements the manual sorting of items by columns.
    class ListViewItemComparer : IComparer
    {
        private int col;
        public ListViewItemComparer()
        {
            col = 0;
        }
        public ListViewItemComparer(int column)
        {
            col = column;
        }
        public int Compare(object x, object y)
        {
            string xStr=((System.Windows.Forms.ListViewItem)x).SubItems[col].Text;
            string yStr=((System.Windows.Forms.ListViewItem)y).SubItems[col].Text;
            int xInt;
            if(int.TryParse(xStr,out xInt))
            {
                int yInt=int.Parse(yStr);
                return xInt-yInt;
            }

            return String.Compare(xStr, yStr);
        }
    }


}
